const defaultFormThead = [
    { key: "entNo", name: "客户编码" },
    { key: "entName", name: "客户名称" },
    { key: "peoName", name: "法定代表人" },
    { key: "telephone", name: "联系电话" },
    { key: "createUserName", name: "创建人" },
    { key: "createTime", name: "创建时间" ,
    formatter:row=>{
        if(row.createTime){
            return (new Date(row.createTime)).toLocaleString();
        }else{
            return '';
        }
    }
}
    
  ];

export default {
    name: "taskCondition",
    
    data() {
        return {
            key: 1,
            showItemList: defaultFormThead,
            allItemList: defaultFormThead,
            checkAll: true,
            isIndeterminate: false,
            formShow:false,
            ids: [],
            searchForm: {
                entName: '',
            },
            tableData: [],
            pager: {
                page: 0,
                size: 20,
                total: 0
            },
        }
    },
    computed: {
        height() {
            return `calc(100vh - 350px)`;
        }
    },
    mounted() {
        this.getList();
    },
    methods: {
        handleCheckedChange(value) {
            let checkedCount = value.length;
            this.checkAll = checkedCount === defaultFormThead.length;
            this.isIndeterminate =
              checkedCount > 0 && checkedCount < defaultFormThead.length;
          },
          handleCheckAllChange(val) {
            this.showItemList = val ? defaultFormThead : [];
            this.isIndeterminate = false;
          },
          handleDownload() {
            this.downloadLoading = true;
            import("@/vendor/Export2Excel").then(excel => {
              const tHeader = [
                "序号",
                "真实姓名",
                "登陆账号",
                "固定电话",
                "启用状态",
                "创建日期"
              ];
              const filterVal = [
                "id",
                "realName",
                "username",
                "telephone",
                "userStatus",
                "createTime"
              ];
              const data = this.formatJson(filterVal, this.tableData);
              excel.export_json_to_excel({
                header: tHeader,
                data,
                filename: "table-list-user"
              });
              this.downloadLoading = false;
            });
          },
          formatJson(filterVal, jsonData) {
            return jsonData.map(v =>
              filterVal.map(j => {
                if (j === "timestamp") {
                  return parseTime(v[j]);
                } else {
                  return v[j];
                }
              })
            );
          },
      
        dateFormatter(row){
            return this.formatDate(row.createTime,"yyyy-MM-dd");
        },
        addEntBase(){
            this.$router.push({path:"/ent/tab"});
        },
        view(row){
            this.$router.push({path: '/ent/entDisplay/entMain', query: {entId: row.id}});
        },
        edit(row){
            this.$message({
                type: 'error',
                message: "功能开发中"
            });
        },
        // 获取条件列表
        getList: function () {
            let params = {
                page: this.pager.page === 0 ? this.pager.page : this.pager.page - 1,
                size: this.pager.size,
                entName:this.searchForm.entName
            };
            this.$api.formPost( '/api/biz/ent/doGetListByFr',params).then(res => {
                if(res.retHead.code=="0000000"){
                    this.tableData = res.retBody.list;
                    this.pager.total = res.retBody.total;
                   
                }else{
                    this.$message({
                        type: 'error',
                        message: res.retHead.message
                    });
                }
            });
        },
        handleSelectionChange: function(val){
            this.ids = val;
        },
        handleSizeChange(val) {
            this.pager.size = val;
        },
        handleCurrentChange(val) {
            this.pager.page = val;
        },
    }
}
